<?php
/**
 * Created by PhpStorm.
 * User: Da Xiong
 * Date: 2018/12/5
 * Time: 9:57
 */

namespace App\Http\Controllers;


use App\Models\Mall;
use Carbon\Carbon;

class ShopController extends Controller
{

    /**
     * 获取商品列表
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(){
        $list = Mall::select('id','name','prices','score','number','thumb','status','changed','sort','created_at','updated_at')
            ->where('status',Mall::STATUS_1)
            ->orWhere(function($query){
                $query->where('status',Mall::STATUS_2)->where('updated_at','>=',Carbon::today());
            })
            ->orderBy('id','DESC')
            ->orderBy('sort','DESC')
            ->get()
            ->chunk(2);
        return $this->returnJson(0,'',$list);
    }

    /**
     * 获取商品详情 [{"name":"2.jpg","url":"http:\/\/qiniu.daduiz.xiegangsir.com\/2018-12-10\/423b7a6cbf3a687fc5638031adb31ce8.jpg","uid":1544435391689,"status":"success"},{"name":"1.jpg","url":"http:\/\/qiniu.daduiz.xiegangsir.com\/2018-12-10\/33458505792cd2c66a38ae0d9f7e4ddc.jpg","uid":1544435400719,"status":"success"},{"name":"0.jpg","url":"http:\/\/qiniu.daduiz.xiegangsir.com\/2018-12-10\/7f5df456c2fd73aa3541a263e7614b9d.jpg","uid":1544435407834,"status":"success"}]
     * @return \Illuminate\Http\JsonResponse
     */
    public function info(){
        $id = (int)request('id',0);
        $info = Mall::find($id);
        if($info){
            return $this->returnJson(0,'',$info);
        }
        return $this->returnJson(1,'error');
    }


}